package com.sanhuo.idms.dao.provider;

import com.sanhuo.idms.entity.Clas;
import com.sanhuo.triild.provider.BaseProvider;
import com.sanhuo.triild.provider.SQL;
import com.sanhuo.utils.basic.BeanUtil;
import com.sanhuo.utils.basic.ReflectionUtil;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class ClasProvider extends BaseProvider {

    public String insert(Clas clas) {
        List<String> condition = new ArrayList<>();
        List<String> condition_ps = new ArrayList<>();
        Field[] fields = ReflectionUtil.getFieldList(clas);
        for (Field field : fields) {
            if (BeanUtil.isNotNull(ReflectionUtil.getFieldValue(clas, field))) {
                condition.add(field.getName());
                condition_ps.add("#{" + field.getName() + "}");
            }
        }
        SQL sql = getSQL();
        sql.insert("clas").Insert_column(condition.toArray(new String[0]))
                .value(condition_ps.toArray(new String[0]));
        return sql.build();
    }



}
